package com.woniu.serviceprice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.internalcommon.dto.PriceRule;
import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.request.PriceRuleIsNewRequest;
import com.woniu.internalcommon.response.PriceRulePage;
import com.woniu.serviceprice.service.PriceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 计价规则相关
 * @Author:  zcnovice
 * @date:  2025/7/9 下午6:58
 */
/* 标识这是一个Spring MVC控制器，会自动将返回对象转为JSON */
@RestController
@RequestMapping("/price-rule")
/* 计价规则 */
public class PriceRuleController {

    @Autowired
    PriceRuleService priceRuleService;

    /*  添加计价规则 */
    @PostMapping("/add")
    //看一下PriceRule类
    public ResponseResult add(@RequestBody PriceRule priceRule){

        return priceRuleService.add(priceRule);
    }

    /* 编辑计价规则 */
    @PostMapping("/edit")
    public ResponseResult edit(@RequestBody PriceRule priceRule){
        return priceRuleService.edit(priceRule);
    }

    /**
     * 查询最新的计价规则
     * @param fareType
     * @return
     */
    /* 需要传入一个String类型的版本编号 */
    @GetMapping("/get-newest-version")
    public ResponseResult<PriceRule> getNewestVersion(@RequestParam("fareType") String fareType){
        return priceRuleService.getNewestVersion(fareType);
    }


    /**
     * 判断规则是否是最新
     * @param priceRuleIsNewRequest
     * @return
     */
    /* PriceRuleIsNewRequest里面包含fareVersion和fareType（当前数据的版本） */
    @PostMapping("/is-new")
    public ResponseResult<Boolean> isNew(@RequestBody PriceRuleIsNewRequest priceRuleIsNewRequest){

        return priceRuleService.isNew(priceRuleIsNewRequest.getFareType(),priceRuleIsNewRequest.getFareVersion());
    }


    /**
     * 判断该城市和对应车型的计价规则是否存在
     * @param priceRule
     * @return
     */
    /* 判断计价规则是否存在 */
    @PostMapping("/if-exists-old")
    public ResponseResult<Boolean> ifExists_old(@RequestBody PriceRule priceRule){
        return priceRuleService.ifExists_old(priceRule);
    }


    /**
     * 判断该城市和对应车型的计价规则是否存在
     * @return
     */
    /* 判断计价规则是否存在 */
/*
    @PostMapping("/if-exists")
    public ResponseResult<Boolean> ifExists(@RequestParam(value = "cityCode")String cityCode,@RequestParam(value = "vehicleType")String vehicleType){
        return priceRuleService.ifExists(cityCode,vehicleType);
    }
*/

    @GetMapping("/if-exists/{cityCode}/{vehicleType}")
    public ResponseResult<Boolean> ifExists(@PathVariable(value = "cityCode")String cityCode,@PathVariable(value = "vehicleType")String vehicleType){
        return priceRuleService.ifExists(cityCode,vehicleType);
    }

    /**
     * @Description:  条件查询(所有)计价规则
     * @Author:  zcnovice
     * @date:  2025/7/14 上午11:09
     */
    @PostMapping("/query")
    public ResponseResult<Page<PriceRule>> query(@RequestBody PriceRulePage priceRulePage){



        Integer current = priceRulePage.getCurrent();
        Integer size = priceRulePage.getSize();
        PriceRule priceRule = priceRulePage.getPriceRule();

        return priceRuleService.getPriceRulesByConditions(current, size,priceRule);
    }

    /**
     * @Description:  删除计价规则
     * @Author:  zcnovice
     * @date:  2025/7/14 上午11:10
     */
    @DeleteMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id){
        return priceRuleService.delete(id);
    }


}